/**
 * Created by renzhiqiang on 2018/1/17.
 */
import * as addDome from '../../services/dome/index';
import {openNotice} from './../../utils'
export default {
  namespace: 'addDome',
  state: {
    visible:false,
    detail:{},
    country:[],
    paramsData:{},
  },
  reducers: {
    save(state, { payload }) {
      return {...state, ...payload};
    }
  },
  effects: {
    // 初始化,准备页面必备的数据源
    *init({ payload }, { call, put }) {
      const country= yield call(addDome.fetchCountry,payload);
      yield put({type: 'save', payload: {country:country.data}});
    },
    *send({ payload }, { call, put }) {
      yield put({type: 'save', payload: {...payload}});
      // yield put({type: 'init', payload: {}});
      if(payload.id==0){
        yield put({type: 'save', payload: {detail:{}}});
      }else {
         const detail= yield call(addDome.fetchDetail,payload);
         yield put({type: 'save', payload: {detail:detail.data}});
      }
    },
    *add({ payload }, { call, put }) {
      const data= yield call(addDome.save,payload);
      openNotice('success', '提示', "保存成功");
      yield put({type: 'save', payload: {visible: false}});
      yield put({type: 'menus/fetch', payload: {pageParam: {pageNo: 1, pageSize: 10, keyword: ''}}});
    }
  },
  subscriptions: {},
};
